package team.lourd.network.system.config;

import com.mongodb.MongoClient;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.MongoDbFactory;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.SimpleMongoDbFactory;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import team.lourd.network.system.own.repository.jpa.netel.NEDiagramRepository;

import java.net.UnknownHostException;

@Configuration
@EnableMongoRepositories(basePackages = "team.lourd.network.system.own.repository.mongo",
        mongoTemplateRef = "template"
)
public class MongoTestConfig {
    @Bean
    public MongoClient mongo() throws UnknownHostException {
        return new MongoClient("192.168.0.102", 27017);
    }

    @Bean
    public MongoDbFactory mongoDbFactory() throws UnknownHostException {
        return new SimpleMongoDbFactory(mongo(), "network_system");
    }

    @Bean
    public MongoTemplate template() throws UnknownHostException {
        return new MongoTemplate(mongoDbFactory());
    }
}